package com.yenlien.traceyun.plant.dao;


import com.yenlien.traceyun.plant.entity.FruitData;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author jialong
 * @date 2021/10/17
 * @description:
 **/

public interface FruitDataDao extends BaseJpaDao<FruitData> {



    @Query(value = "SELECT * FROM t_fruit_data WHERE type = ?1 AND variety = ?2 ORDER BY create_time DESC LIMIT 1", nativeQuery = true)
    FruitData getFirstByTypeAndVariety(String type, String variety);


    @Query(value = "SELECT * FROM t_fruit_data WHERE type = ?1 ORDER BY create_time DESC LIMIT ?2", nativeQuery = true)
    List<FruitData> getListByType(String type, Integer limit);


    @Query(value = "SELECT * FROM t_fruit_data WHERE type = ?1 AND create_time >= ?2 ORDER BY create_time DESC", nativeQuery = true)
    List<FruitData> getByType(String type, String time);

    @Query(value = "SELECT * FROM t_fruit_data WHERE type = ?1 AND (create_time >= ?2 AND create_time <= ?3) ORDER BY create_time DESC", nativeQuery = true)
    List<FruitData> getByType(String type, String startTime, String endTime);


}
